package guiclient;

import client.Client;
import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Constants;
import model.MessageCommunication;
import model.User;

public class GUILogin extends javax.swing.JFrame {

    private Color colorBackgroud = new Color(240, 240, 240);
    private GUIError error = new GUIError();
    private MessageCommunication response;
    private Client clientSession = new Client();
    private GUIChatPrincipal principal = new GUIChatPrincipal();
    private User user;

    public GUILogin() {
        initComponents();
        getContentPane().setBackground(colorBackgroud);
    }

    public GUIChatPrincipal getChatPrincipal() {
        return principal;
    }

    public void setGUIChatPrincipal(GUIChatPrincipal chat) {
        principal = chat;
    }

    public void setConstantsConnection() {
        Constants.setServerHost(ipServerConnectionJTextField.getText());
        String portString = portServerConnectionJTextField.getText();
        try {
            int portInteger = Integer.parseInt(portString);
            if (portInteger > 0 && portInteger < 65535) {
                Constants.setServerPort(portInteger);
            } else {
                error.setErrorMessage("El puerto especificado no es válido");
                error.setVisible(true);
            }
        } catch (NumberFormatException ex) {
            error.setErrorMessage("El puerto especificado no es válido");
            error.setVisible(true);
            Logger.getLogger(GUILogin.class.getName()).log(Level.SEVERE,
                    "No se especificó un puerto válido para realizar la conexión", ex);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        newUserFrame = new javax.swing.JFrame();
        newUserNameJLabel = new javax.swing.JLabel();
        newUserNameJTextField = new javax.swing.JTextField();
        newUserEmailJLabel = new javax.swing.JLabel();
        newUserEmailJTextField = new javax.swing.JTextField();
        newUserPass1JLabel = new javax.swing.JLabel();
        newUserPass1JPasswordField = new javax.swing.JPasswordField();
        newUserPass2JLabel = new javax.swing.JLabel();
        newUserCancel = new javax.swing.JButton();
        newUserCreate = new javax.swing.JButton();
        newUserNickNameJLabel = new javax.swing.JLabel();
        newUserNickNameJTextField = new javax.swing.JTextField();
        newUserPass2JPasswordField = new javax.swing.JPasswordField();
        connectionOptions = new javax.swing.JFrame();
        ipServerConnectionJLabel = new javax.swing.JLabel();
        ipServerConnectionJTextField = new javax.swing.JTextField();
        portServerConnectionJLabel = new javax.swing.JLabel();
        portServerConnectionJTextField = new javax.swing.JTextField();
        acceptConnectionJButton = new javax.swing.JButton();
        cancelConnectionJButton = new javax.swing.JButton();
        imageJLabel = new javax.swing.JLabel();
        userNameJLabel = new javax.swing.JLabel();
        userNameJTextField = new javax.swing.JTextField();
        userPassJLabel = new javax.swing.JLabel();
        userPassJPasswordField = new javax.swing.JPasswordField();
        initSessionJButton = new javax.swing.JButton();
        newUserJButton = new javax.swing.JButton();
        newUserJLabel = new javax.swing.JLabel();
        cancelInitSessionJButton = new javax.swing.JButton();
        loginJMenuBar = new javax.swing.JMenuBar();
        optionsLoginJMenuBar = new javax.swing.JMenu();
        connectionOptionsJMenuItem = new javax.swing.JMenuItem();
        exitOptionsJMenuItem = new javax.swing.JMenuItem();

        newUserFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        newUserFrame.setTitle("¡¡¡Create una cuenta en CEU-Messenger!!!");
        newUserFrame.setLocationByPlatform(true);
        newUserFrame.setMinimumSize(new java.awt.Dimension(410, 265));
        newUserFrame.setResizable(false);

        newUserNameJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        newUserNameJLabel.setText("Nombre:");

        newUserEmailJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        newUserEmailJLabel.setText("E-mail:");

        newUserPass1JLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        newUserPass1JLabel.setText("Contraseña:");

        newUserPass2JLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        newUserPass2JLabel.setText("Repite Contraseña:");

        newUserCancel.setText("Cancelar");
        newUserCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newUserCancelActionPerformed(evt);
            }
        });

        newUserCreate.setText("¡¡¡Crear!!!");
        newUserCreate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newUserCreateActionPerformed(evt);
            }
        });

        newUserNickNameJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        newUserNickNameJLabel.setText("NickName:");

        javax.swing.GroupLayout newUserFrameLayout = new javax.swing.GroupLayout(newUserFrame.getContentPane());
        newUserFrame.getContentPane().setLayout(newUserFrameLayout);
        newUserFrameLayout.setHorizontalGroup(
            newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newUserFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(newUserFrameLayout.createSequentialGroup()
                        .addComponent(newUserCreate, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(newUserCancel, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE))
                    .addGroup(newUserFrameLayout.createSequentialGroup()
                        .addGroup(newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(newUserPass2JLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(newUserNameJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(newUserNickNameJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(newUserEmailJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(newUserPass1JLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(newUserNameJTextField)
                            .addComponent(newUserNickNameJTextField)
                            .addComponent(newUserEmailJTextField)
                            .addComponent(newUserPass1JPasswordField)
                            .addComponent(newUserPass2JPasswordField))))
                .addContainerGap())
        );
        newUserFrameLayout.setVerticalGroup(
            newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newUserFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newUserNameJTextField)
                    .addComponent(newUserNameJLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newUserNickNameJLabel)
                    .addComponent(newUserNickNameJTextField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newUserEmailJLabel)
                    .addComponent(newUserEmailJTextField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newUserPass1JLabel)
                    .addComponent(newUserPass1JPasswordField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newUserPass2JLabel)
                    .addComponent(newUserPass2JPasswordField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(newUserFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newUserCreate)
                    .addComponent(newUserCancel))
                .addContainerGap())
        );

        connectionOptions.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        connectionOptions.setTitle("Configuración de la Conexión");
        connectionOptions.setLocationByPlatform(true);
        connectionOptions.setMinimumSize(new java.awt.Dimension(400, 149));
        connectionOptions.setResizable(false);

        ipServerConnectionJLabel.setText("Dirección IP del Servidor:");

        ipServerConnectionJTextField.setText("localhost");

        portServerConnectionJLabel.setText("Puerto del Servidor:");

        portServerConnectionJTextField.setText("9000");

        acceptConnectionJButton.setText("Aceptar");
        acceptConnectionJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acceptConnectionJButtonActionPerformed(evt);
            }
        });

        cancelConnectionJButton.setText("Cancelar");
        cancelConnectionJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelConnectionJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout connectionOptionsLayout = new javax.swing.GroupLayout(connectionOptions.getContentPane());
        connectionOptions.getContentPane().setLayout(connectionOptionsLayout);
        connectionOptionsLayout.setHorizontalGroup(
            connectionOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(connectionOptionsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(connectionOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(connectionOptionsLayout.createSequentialGroup()
                        .addGroup(connectionOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(ipServerConnectionJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(portServerConnectionJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(connectionOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ipServerConnectionJTextField)
                            .addComponent(portServerConnectionJTextField)))
                    .addGroup(connectionOptionsLayout.createSequentialGroup()
                        .addComponent(acceptConnectionJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelConnectionJButton, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)))
                .addContainerGap())
        );
        connectionOptionsLayout.setVerticalGroup(
            connectionOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(connectionOptionsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(connectionOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ipServerConnectionJLabel)
                    .addComponent(ipServerConnectionJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(connectionOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(portServerConnectionJLabel)
                    .addComponent(portServerConnectionJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(connectionOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(acceptConnectionJButton)
                    .addComponent(cancelConnectionJButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("CEU-Messenger");
        setLocationByPlatform(true);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        imageJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        imageJLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUIClient/Images/chat-icon.png"))); // NOI18N

        userNameJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        userNameJLabel.setText("Introduce tu email:");

        userNameJTextField.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        userPassJLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        userPassJLabel.setText("Contraseña:");

        userPassJPasswordField.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        initSessionJButton.setText("Iniciar Sesión");
        initSessionJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                initSessionJButtonActionPerformed(evt);
            }
        });

        newUserJButton.setText("¡¡¡Regístrate!!!");
        newUserJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newUserJButtonActionPerformed(evt);
            }
        });

        newUserJLabel.setText("¿No tienes cuenta?");

        cancelInitSessionJButton.setText("Cancelar");
        cancelInitSessionJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelInitSessionJButtonActionPerformed(evt);
            }
        });

        optionsLoginJMenuBar.setText("Opciones");

        connectionOptionsJMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/guiclient/images/connection30.png"))); // NOI18N
        connectionOptionsJMenuItem.setText("Conexión");
        connectionOptionsJMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connectionOptionsJMenuItemActionPerformed(evt);
            }
        });
        optionsLoginJMenuBar.add(connectionOptionsJMenuItem);

        exitOptionsJMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/guiclient/images/exit30.png"))); // NOI18N
        exitOptionsJMenuItem.setText("Salir");
        optionsLoginJMenuBar.add(exitOptionsJMenuItem);

        loginJMenuBar.add(optionsLoginJMenuBar);

        setJMenuBar(loginJMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(imageJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(userNameJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(userNameJTextField)
                    .addComponent(userPassJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(userPassJPasswordField)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(newUserJLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(newUserJButton))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(initSessionJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelInitSessionJButton, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imageJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(userNameJLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(userNameJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(userPassJLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(userPassJPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(initSessionJButton)
                    .addComponent(cancelInitSessionJButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 165, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newUserJButton)
                    .addComponent(newUserJLabel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelInitSessionJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelInitSessionJButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_cancelInitSessionJButtonActionPerformed

    private void newUserCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newUserCancelActionPerformed
        newUserFrame.setVisible(false);
    }//GEN-LAST:event_newUserCancelActionPerformed

    private void newUserJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newUserJButtonActionPerformed
        newUserFrame.setVisible(true);
        newUserFrame.getContentPane().setBackground(colorBackgroud);
    }//GEN-LAST:event_newUserJButtonActionPerformed

    private void connectionOptionsJMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectionOptionsJMenuItemActionPerformed
        connectionOptions.setVisible(true);
        connectionOptions.getContentPane().setBackground(colorBackgroud);
    }//GEN-LAST:event_connectionOptionsJMenuItemActionPerformed

    private void acceptConnectionJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptConnectionJButtonActionPerformed
        setConstantsConnection();
    }//GEN-LAST:event_acceptConnectionJButtonActionPerformed

    private void cancelConnectionJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelConnectionJButtonActionPerformed
        connectionOptions.setVisible(false);
    }//GEN-LAST:event_cancelConnectionJButtonActionPerformed

    private void newUserCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newUserCreateActionPerformed
        String pass1 = new String(newUserPass1JPasswordField.getPassword());
        String pass2 = new String(newUserPass2JPasswordField.getPassword());
        if (pass1.equals(pass2)) {
            user = new User(newUserNameJTextField.getText(), newUserNickNameJTextField.getText(),
                    newUserEmailJTextField.getText(), new String(newUserPass1JPasswordField.getPassword()), false);
            response = clientSession.createNewUser(user);
        } else {
            response = new MessageCommunication(null, "Las contraseñas no son iguales...");
        }
        if (!response.getStatus() || response.getStatus() == null) {
            error.setErrorMessage(response.getMessage());
            error.setVisible(true);
        }
        newUserFrame.setVisible(false);
    }//GEN-LAST:event_newUserCreateActionPerformed

    private void initSessionJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_initSessionJButtonActionPerformed
        user = new User();
        user.setUserEmail(userNameJTextField.getText());
        user.setUserPassword(new String(userPassJPasswordField.getPassword()));
        response = clientSession.loginUser(user);
        if (response.getStatus()) {
            principal.setSession(clientSession);
            clientSession.getSession().setGUIChatPrincipal(principal);
            principal.setVisible(true);
            setVisible(false);
        } else {
            error.setErrorMessage(response.getMessage());
            error.setVisible(true);
        }
    }//GEN-LAST:event_initSessionJButtonActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
    }//GEN-LAST:event_formWindowClosed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        System.exit(0);
    }//GEN-LAST:event_formWindowClosing

    public static void main(String args[]) {

        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
                javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUILogin.class.getName()).log(java.util.logging.Level.WARNING,
                    "Fallo al iniciar la ventana de login del chat", ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new GUILogin().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton acceptConnectionJButton;
    private javax.swing.JButton cancelConnectionJButton;
    private javax.swing.JButton cancelInitSessionJButton;
    private javax.swing.JFrame connectionOptions;
    private javax.swing.JMenuItem connectionOptionsJMenuItem;
    private javax.swing.JMenuItem exitOptionsJMenuItem;
    private javax.swing.JLabel imageJLabel;
    private javax.swing.JButton initSessionJButton;
    private javax.swing.JLabel ipServerConnectionJLabel;
    private javax.swing.JTextField ipServerConnectionJTextField;
    private javax.swing.JMenuBar loginJMenuBar;
    private javax.swing.JButton newUserCancel;
    private javax.swing.JButton newUserCreate;
    private javax.swing.JLabel newUserEmailJLabel;
    private javax.swing.JTextField newUserEmailJTextField;
    private javax.swing.JFrame newUserFrame;
    private javax.swing.JButton newUserJButton;
    private javax.swing.JLabel newUserJLabel;
    private javax.swing.JLabel newUserNameJLabel;
    private javax.swing.JTextField newUserNameJTextField;
    private javax.swing.JLabel newUserNickNameJLabel;
    private javax.swing.JTextField newUserNickNameJTextField;
    private javax.swing.JLabel newUserPass1JLabel;
    private javax.swing.JPasswordField newUserPass1JPasswordField;
    private javax.swing.JLabel newUserPass2JLabel;
    private javax.swing.JPasswordField newUserPass2JPasswordField;
    private javax.swing.JMenu optionsLoginJMenuBar;
    private javax.swing.JLabel portServerConnectionJLabel;
    private javax.swing.JTextField portServerConnectionJTextField;
    private javax.swing.JLabel userNameJLabel;
    private javax.swing.JTextField userNameJTextField;
    private javax.swing.JLabel userPassJLabel;
    private javax.swing.JPasswordField userPassJPasswordField;
    // End of variables declaration//GEN-END:variables
}
